package com.example;

import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.CreateTopicsResult;
import org.apache.kafka.clients.admin.NewTopic;

import java.util.Collections;
import java.util.Properties;
import java.util.concurrent.ExecutionException;

public class KafkaAdmin {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        String broker="192.168.35.101:9094";
        String topic="admin-topic";
        Properties properties = new Properties();
        properties.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,broker);
        properties.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG,30000);

        AdminClient adminClient = AdminClient.create(properties);

        NewTopic newTopic = new NewTopic(topic,4,(short)2);
        CreateTopicsResult result = adminClient.createTopics(Collections.singleton(newTopic));

        result.all().get();
        adminClient.close();

    }
}
